Refactor: unify image export format/encoding into ImageExportFormat + NSImage.encoded#13
Merged
Merged
Conversation
… NSImage.encoded EditorView.writeImageSync chose PNG vs JPEG-0.9 by file extension and inlined both encoders; the JPEG branch duplicated CaptureManager.saveJPEG, and CaptureHistoryStore.writeThumbnail duplicated both the JPEG encoder and the thumbnail sizing math (the latter already extracted as ThumbnailGeometry in #10). Add ImageExportFormat (.png / .jpeg(quality), plus .forPath(_:) extension decision) and a single NSImage.encoded(as:) encoder. Rewire all three call sites: EditorView.writeImageSync, CaptureManager.saveJPEG, and CaptureHistoryStore.writeThumbnail (now also using ThumbnailGeometry). Behavior-preserving. Adds ImageExportFormatTests (8 cases) covering the path decision and PNG/JPEG signatures of the encoded data.
GamalAnwar
added a commit
that referenced
this pull request
Jun 18, 2026
… NSImage.encoded (#13) Add ImageExportFormat (.png/.jpeg(quality) + .forPath decision) and a single NSImage.encoded(as:) encoder. Collapse three inline/duplicated image encoders (EditorView.writeImageSync, CaptureManager.saveJPEG, CaptureHistoryStore. writeThumbnail) onto it, and route the history thumbnail's sizing through ThumbnailGeometry too. Behavior-preserving. Adds ImageExportFormatTests (8 cases). CI green.
GamalAnwar
added a commit
that referenced
this pull request
Jun 18, 2026
… NSImage.encoded (#13) Add ImageExportFormat (.png/.jpeg(quality) + .forPath decision) and a single NSImage.encoded(as:) encoder. Collapse three inline/duplicated image encoders (EditorView.writeImageSync, CaptureManager.saveJPEG, CaptureHistoryStore. writeThumbnail) onto it, and route the history thumbnail's sizing through ThumbnailGeometry too. Behavior-preserving. Adds ImageExportFormatTests (8 cases). CI green.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Target 2 (the editor export/save pipeline).
EditorView.writeImageSyncchose PNG vs JPEG-0.9 by file extension and inlined both encoders. That JPEG branch duplicatedCaptureManager.saveJPEG, andCaptureHistoryStore.writeThumbnailduplicated both the JPEG encoder and the thumbnail sizing math — the latter already extracted asThumbnailGeometryin #10. So this slice collapses three copies of "encode an NSImage to data" down to one.New
Utils/ImageExportFormat.swift:Call sites rewired
EditorView.writeImageSync— the extensionif/inline encoders becomeimage.encoded(as: .forPath(path)).CaptureManager.saveJPEG—image.encoded(as: .jpeg(quality: quality)).CaptureHistoryStore.writeThumbnail— now usesThumbnailGeometry.fittedSize(...)for sizing andthumb.encoded(as: .jpeg(quality: 0.7))for encoding (previously a full re-implementation of both).Scope / safety
lowercased()), identical compression factors (0.9 editor / 0.7 thumbnails), identical PNG path via the existingpngData.FileManagerwrites stay at the call sites.Tests
ImageExportFormatTests(8 cases):forPathfor png/jpg/jpeg, case-insensitive matching, unknown/missing extension → png; andencoded(as:)produces data with the correct PNG (\x89PNG) and JPEG (FFD8FF) signatures.🤖 Generated with Claude Code
Generated by Claude Code